Socket
Socket
Sign inDemoInstall

arg

Package Overview
Dependencies
Maintainers
164
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arg

Unopinionated, no-frills CLI argument parser


Version published
Maintainers
164
Created

What is arg?

The arg npm package is a simple argument parsing library. It allows developers to parse command-line arguments in Node.js applications into a structured format that is easy to work with. It supports various types of flags and options, including boolean flags, string options, and number options.

What are arg's main functionalities?

Parsing command-line flags and options

This feature allows the parsing of command-line arguments with various types of expected values. The example code demonstrates how to define the expected types for each flag and option, including boolean, count, number, and string types, as well as how to set up aliases for shorthand notation.

{"const arg = require('arg');\n\nconst args = arg({\n  // Types\n  '--help': Boolean,\n  '--version': Boolean,\n  '--verbose': arg.COUNT, // A count of how many times the flag was set\n  '--port': Number, // A port number\n  '--name': String, // A string name\n  // Aliases\n  '-h': '--help',\n  '-v': '--version',\n  '-n': '--name'\n});\n\nconsole.log(args); // Output the parsed arguments"}

Handling default values

This feature allows developers to specify default values for command-line options that are not provided by the user. The example code shows how to set default values for a port and host.

{"const arg = require('arg');\n\nconst args = arg({\n  '--port': Number,\n  '--host': String\n}, {\n  // Default values\n  '--port': 8080,\n  '--host': 'localhost'\n});\n\nconsole.log(args); // Output the parsed arguments with defaults"}

Permissive parsing

This feature enables permissive parsing, which means that the parser will ignore any flags that are not explicitly defined in the schema. The example code shows how to enable permissive parsing.

{"const arg = require('arg');\n\nconst args = arg({\n  '--port': Number,\n  '--host': String\n}, {\n  permissive: true\n});\n\nconsole.log(args); // Output the parsed arguments, ignoring any non-specified flags"}

Other packages similar to arg

FAQs

Package last updated on 05 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc